<template>
  <div class="activity">
    <page-header title="活动"></page-header>
    <scroll class="content" :data="list" ref="scroll" :class="{'loading': loading}"
      :pullup="true" :pulldown="true" @scrollToEnd="_more" @pullingDown="_refash">
      <ul class="list" >
        <li v-for="(item, index) in list" :key="index" class="item">
          <div class="pic" >
            <img :src="item.bean.picture" >
          </div>
          <div class="info">
            <p class="title">{{item.bean.name}}</p>
            <p class="des">{{item.bean.acabstract}}</p>
          </div>
          <div class="price">
            <p class="value">¥{{item.bean.money}}</p>
            <div class="turnBtn" @click="_turn(item)">查看详情</div>
          </div>
        </li>
        <p class="nomore" v-if="nomore">没有更多</p>
      </ul>
    </scroll>
    <router-view></router-view>
  </div>
</template>

<script type="text/ecmascript-6">
import PageHeader from 'components/page-header'
import Scroll from 'components/scroll/scroll'
import * as exampleApi from 'api/example'
export default {
  components: {
    PageHeader,
    Scroll
  },
  data () {
    return {
      list: [],
      page: 1,
      pageSize: 10,
      actype: '',
      title: '',
      text: '',
      loading: false,
      nomore: false
    }
  },
  created() {
    this.id = this.$route.params.id
    this.actype = this.$route.params.actype
    if (this.actype === ':actype') {
      this.actype = ''
    }
    this.title = this.$route.query.title
    if (this.title === null || this.title === undefined || this.title === 'undefined') {
        this.title = ''
    }
    this._initData()
  },
  methods: {
    _more() {
      if (this.nomore) {
        return
      }
      this.page ++
      this._initData()
    },
    _refash() {
      this.page = 1
      this.loading = true
      this.nomore = false
      this._initData()
    },
    _initData() {
      exampleApi.modePost('/api/public/wz/activity/list', {
        orgId: sessionStorage.getItem('siteId'),
        actype: this.actype,
        title: this.title,
        pageNo: this.page,
        pageSize: this.pageSize
      }).then(res => {
        if (res.data.data.rows.length < this.pageSize) {
          this.nomore = true
        }
        if (this.page === 1) {
            this.list = res.data.data.rows
        } else if (this.page > 1) {
            this.list = this.list.concat(res.data.data.rows)
        }
      })
      .catch(error => {
        console.log(error)
      })
    },
    _turn(item) {
      this.$router.push({
				path: `/activity/detail${item.bean.id}:0`
			})
    }
  }
}

</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
  .activity{
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    background-color: #e6e6e6;
    .content{
      position: relative;
      height:calc(~"100% - 84px");
      overflow: hidden;
      &::after {
        position: absolute;
        display: none;
        content: '';
        top: 10px;
        left: 0;
        width: 100%;
        height: 40px;
        text-align: center;
        background: url('../assets/image/loading.gif') no-repeat center / 40px auto;
      }
      .list{
        position: relative;
        z-index: 2;
        display: flex;
        flex-direction: column;
        width: 100%;
      }
      .item{
        width: 100%;
        height: 160px;
        background-color: #ffffff;
        box-sizing:border-box;
        padding: 20px;
        margin-bottom: 20px;
        display: flex;
        font-family: PingFang;
        .pic{
          width: 155px;
          height: 100%;
          background-color: #ffffff;
          border-radius: 12px;
          overflow: hidden;
          img{
            width: 100%;
            height: 100%;
          }
        }
        .info{
          flex:1;
          padding: 0 20px;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          .title{
            padding: 10px 0;
            font-weight: bold;
            font-size: 26px;
            color: #333333;
          }
          .des{
            font-size: 20px;
            line-height: 30px;
            color: #999999;
            overflow: hidden;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical
          }
        }
        .price{
          flex: 0 0 140px;
          display: flex;
          align-items: center;
          flex-direction: column;
          justify-content: space-between;
          border-left: 1px solid #ccc;
          box-sizing: border-box;
          padding-left: 20px;
          .value{
            font-size: 32px;
            color: #ff0015;
          }
          .turnBtn{
            width: 120px;
            height: 50px;
            background-color: #419eff;
            border-radius: 6px;
            line-height: 50px;
            text-align: center;
            color: #fff;
          }
        }
      }
      .nomore{
        font-size: 22px;
        color: #999999;
        text-align: center;
        padding-bottom: 20px;
      }
    }
    .content.loading{
      &::after {
        display: block;
      }
    }
  }
</style>
